#encoding=utf-8

#练习题

def equi(A):
    '''unit test
    >>> equi([-7, 1, 5, 2, -4, 3, 0])
    6
    '''
    if len(A) == 0:
      return -1    
    
    B = []
    sum = 0
    for i in xrange(len(A)):
      sum = sum + A[i]
      B.append(sum)
      
    if sum - A[0] == 0:
      return 0
    if sum - A[-1] == 0:
      return len(A) - 1
      
    for j in xrange(1, len(A) - 1):
      if B[j-1]*2 == (sum - A[j]):
        return j
    
    return -1

import doctest
doctest.testmod()
